//import com.arakelian.faker.model.Person;
//import com.arakelian.faker.service.RandomPerson;
//import org.apache.commons.lang3.RandomUtils;
//import org.springframework.util.StopWatch;
//
//import java.nio.file.Files;
//import java.nio.file.Path;
//import java.util.concurrent.*;
//
//public class GenerateTestData {
//
//    /**
//     * <dependency>
//     * <groupId>com.arakelian</groupId>
//     * <artifactId>faker</artifactId>
//     * <version>4.0.1</version>
//     * </dependency>
//     */
//
//    public static void main(String[] args) {
////        genUid();
////        genFeedId();
//    }
//
//    // 多线程生成1亿用户
//    public static void genUid() {
//        ExecutorService executorService = executorService();
//        CompletableFuture<Void>[] task = new CompletableFuture[10];
//
//        for (int i = 0; i < 10; i++) {
//            int finalI = i;
//            Runnable runnable = () -> {
//                long start = finalI * 10000000L + 6000106883L;
//                long end = start + 10000000L;
//                String filepath = "D:\\data\\pcc\\gen_users" + finalI + ".csv";
//                genUsers(start, end, filepath);
//            };
//            CompletableFuture<Void> future = CompletableFuture.runAsync(runnable, executorService);
//            task[i] = future;
//        }
//
//        StopWatch stopWatch = new StopWatch();
//        stopWatch.start();
//        CompletableFuture<Void> future = CompletableFuture.allOf(task);
//        if (future.isDone()) {
//            stopWatch.stop();
//            double totalTimeSeconds = stopWatch.getTotalTimeSeconds();
//            System.out.println(totalTimeSeconds);
//            System.exit(1);
//        }
//    }
//
//    // 多线程生成5000万feed
//    public static void genFeedId() {
//        ExecutorService executorService = executorService();
//        CompletableFuture<Void>[] task = new CompletableFuture[10];
//
//        for (int i = 0; i < 10; i++) {
//            int finalI = i;
//            Runnable runnable = () -> {
//                long start = finalI * 5000000L + 8000100010L;
//                long end = start + 5000000L;
//                String filepath = "D:\\data\\pcc\\gen_feeds" + finalI + ".csv";
//                genFeeds(start, end, filepath);
//            };
//            CompletableFuture<Void> future = CompletableFuture.runAsync(runnable, executorService);
//            task[i] = future;
//        }
//
//        StopWatch stopWatch = new StopWatch();
//        stopWatch.start();
//        CompletableFuture<Void> future = CompletableFuture.allOf(task);
//        if (future.isDone()) {
//            stopWatch.stop();
//            double totalTimeSeconds = stopWatch.getTotalTimeSeconds();
//            System.out.println(totalTimeSeconds);
//            System.exit(1);
//        }
//
//    }
//
//    public static void genFeeds(long start, long end, String filepath) {
//        try {
//            StringBuilder feeds = new StringBuilder();
//            for (long i = start; i < end; i++) {
//                String id = String.valueOf(i);
//                String uid = String.valueOf(RandomUtils.nextLong(6000000000L, 6090106882L));
//                feeds.append(id).append(",").append(uid).append("\n");
//            }
//            // write to gen_users.csv
//            Files.writeString(Path.of(filepath), feeds.toString());
//        } catch (Exception exception) {
//        }
//    }
//
//    public static void genUsers(long start, long end, String filepath) {
//        try {
//            StringBuilder users = new StringBuilder();
//            for (long i = start; i < end; i++) {
//                Person next = RandomPerson.get().next();
//                String personName = name(next.getFirstName()) + " " + name(next.getLastName());
//                String uid = String.valueOf(i);
//                users.append(uid).append(",").append(personName).append(",").append(personName).append("\n");
//            }
//            // write to gen_users.csv
//            Files.writeString(Path.of(filepath), users.toString());
//        } catch (Exception exception) {
//        }
//    }
//
//    public static String name(String name) {
//        if (name == null || name.isEmpty()) {
//            return name;
//        }
//
//        StringBuilder builder = new StringBuilder(name.toLowerCase());
//        builder.setCharAt(0, Character.toUpperCase(builder.charAt(0)));
//        return builder.toString();
//    }
//
//    public static ExecutorService executorService() {
//        int processors = Runtime.getRuntime().availableProcessors();
//        final int minThreads = 2;
//        final int queueSize = 5000;
//        System.out.println("Available processor is " + processors);
//        if (processors < minThreads) {
//            processors = minThreads;
//        }
//        return new ThreadPoolExecutor(processors, processors * 2, 2,
//            TimeUnit.HOURS, new ArrayBlockingQueue<>(queueSize),
//            new ThreadPoolExecutor.CallerRunsPolicy());
//    }
//
//}
